<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<%@ page import = "com.weibo.dao.connDB" %>

    <%
    connDB db = new connDB();
    db.getConnection();
    String sql = "";
   
    /*finish getting*/
    String nickname=request.getParameter("nickname");
    String statement=request.getParameter("statement");   
    String focus = request.getParameter("focus");
	String fans=request.getParameter("fans");
	/*values can be got correctly*/
	
	System.out.println(nickname + statement + focus + fans);
    try
    {
      /*checking same statements*/
      int countRepeat = 1;
      sql = "select * from statements where nickname = '"+nickname+"'and statement='"+statement+"' ";
      db.rs = db.executeQuery(sql);
      while(db.rs.next()){
    	  countRepeat+=1;
    	  
    	  if(countRepeat>1)
    		  response.sendRedirect("home.jsp");}
      
			if(countRepeat<2)
			{
      		sql = "select * from statements";
      		db.rs = db.executeQuery(sql);
      		int count = 1;
      		while(db.rs.next()){count+=1;}
     
      		/*pre action*/
      		db.stmt =db.conn.prepareStatement("insert into statements values(?,?,?)");   
      		//System.out.println("creating");	
      		db.stmt.setInt(1,count);
      		db.stmt.setString(2,nickname);
      		db.stmt.setString(3,statement);
      
      		//System.out.println("seting");	
      		int flag = db.stmt.executeUpdate();
      
     		if(flag==1){
     %>
     	<!--Send element with id?? get it back using id??-->
     	<form method="post" id="rehome" action="home.jsp">
    	 	<input type="hidden" name="nickname" value=<%=nickname%>></input>
     		<input type="hidden" name="focus" value=<%=focus%>></input>
     		<input type="hidden" name="fans" value=<%=fans%>></input>
     		<input type="hidden" name="statement" value=<%=statement%>></input>
     			<script language="JavaScript"> 
				document.getElementById("rehome").submit();
			</script> 
		</form>
     <%
    	
     	session.setAttribute("statement",statement);
    	}else{out.println("<div align=\"center\"><font color=red size=4>no </font></div>");}
      db.close();
 }//if
    }catch(java.sql.SQLException sqle) {
		sqle.printStackTrace();
      out.println(sqle+"222222222222");

    }

    catch(Exception e) {
		e.printStackTrace();
      out.println(e+"33333333333333333333");

    }%>